package com.wdz.mvr.controllers;

import com.wdz.mvr.Services.PopularService;
import com.wdz.mvr.dao.PopularRepository;
import com.wdz.mvr.entities.Classification;
import com.wdz.mvr.entities.Popular;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("populars")
public class PopularController {

    @Autowired
    PopularService popularService;

    @GetMapping
    public String displayPopulars(Model model){

        List<Popular> populars = popularService.getAll();
        model.addAttribute("populars", populars);
        return "populars/list-populars";
    }

    @GetMapping("/new")
    public String displayPopularForms(Model model){

        Popular aPopular = new Popular();
        model.addAttribute("populars",aPopular);
        return "populars/new-popular";
    }

    @PostMapping("/save")
    public String createPopular(Model model, Popular popular){

        popularService.save(popular);
        return "redirect:/populars";
    }
}
